package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.ProductDetailRequest;
import com.mall.shopping.dto.ProductDetailResponse;
import com.mall.user.annotation.Anoymous;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author:tanxin Desc:
 * @date:2020/7/11 8:31
 */
@Slf4j
@RestController
@RequestMapping("/shopping")
@Anoymous
public class ProductDetailController {

    @Reference(timeout = 3000,check = false)
    IProductService productService;

    @GetMapping("/product/{id}")
    public ResponseData queryProductDetailById(@PathVariable Long id){
        ProductDetailRequest detailRequest = new ProductDetailRequest();
        detailRequest.setId(id);
        ProductDetailResponse detailResponse = productService.getProductDetail(detailRequest);
        if (ShoppingRetCode.SUCCESS.getCode().equals(detailResponse.getCode())){
            //成功
            return new ResponseUtil<>().setData(detailResponse.getProductDetailDto());
        }
        return new ResponseUtil<>().setErrorMsg(detailResponse.getMsg());
    }

}
